<footer class="sticky-footer">
    <div class="container">
        <div class="text-center">
            <small>Copyright © Your Website 2017</small>
        </div>
    </div>
</footer>
<!-- Scroll to Top Button-->
<a class="scroll-to-top rounded" href="#page-top">
    <i class="fa fa-angle-up"></i>
</a>
<!-- Logout Modal-->
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
                <button class="close" type="button" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">×</span>
                </button>
            </div>
            <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
            <div class="modal-footer">
                <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
                <a class="btn btn-primary" href="login.html">Logout</a>
            </div>
        </div>
    </div>
</div>
<!-- Bootstrap core JavaScript-->
<script src="/vendor/jquery/jquery.min.js"></script>
<script src="/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="/vendor/jquery-easing/jquery.easing.min.js"></script>

<!-- Custom scripts for all pages-->
<script src="/js/sb-admin.min.js"></script>


<script>
    $(document).ready(function () {
        setTimeout(function () {
            $('.auto-hide').slideUp(300);
        }, 2000);


        $("#create-category-button").on('click', function (e) {
            e.preventDefault();

            var data = $("#category-title").val();

            $.ajax({
                url: '/admin/category/create',
                type: 'POST',
                data: {name: data},
                success: function (response) {

                    var html = `<tr>
                        <td>${response.title}</td>
                        <td class="d-flex justify-content-center">
                            <a href="/admin/category/edit/${response._id}" class="btn btn-sm btn-warning mr-2">Edit</a>
                            <form action="/admin/category/${response._id}?newMethod=DELETE" method="post">
                                <button class="btn btn-sm btn-danger" type="submit">Delete</button>
                            </form>
                        </td>
                    </tr>`;


                    $(".category-list").append(html);

                }
            });

            $("#category-title").val('');
        });


        $("#update-category-button").on('click', function (e) {
            e.preventDefault();

            var data = $("#category-title").val();
            var id = $("#category-id").val();

            $.ajax({
                url: `/admin/category/edit/${id}`,
                type: 'POST',
                data: {name: data},
                success: function (response) {
                    window.location.href = response.url;
                }
            });
        });


    });

</script>